package com.ler.auth.controller;

import com.ler.auth.entity.ClientDO;
import com.ler.auth.service.ClientService;
import com.ler.yrmall.basic.Form;
import com.ler.yrmall.basic.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author Leron
 */
@RestController
@RequestMapping("/client")
public class ClientController {

    @Resource
    private ClientService clientService;

    @GetMapping("/find")
    public Result<?> find(Form request) {
        return Result.ok(clientService.find(request));
    }

    @GetMapping("/getById/{clientId}")
    public Result<?> getById(@PathVariable String clientId) {
        return Result.ok(clientService.getById(clientId));
    }

    @PostMapping("/save")
    public Result<?> save(@RequestBody ClientDO request) {
        return Result.ok(clientService.saveClient(request));
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody ClientDO request) {
        return Result.ok(clientService.updateById(request));
    }

    @RequestMapping("/resetSecret/{clientId}")
    public Result<?> resetSecret(@PathVariable String clientId) {
        return Result.ok(clientService.resetSecret(clientId));
    }

    @RequestMapping("/delete")
    public Result<?> delete(@RequestBody Long[] ids) {
        clientService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
